const express = require('express');
const router = express.Router();
const udao = require("../dao/mysql/UsersDao");
const pdao = require("../dao/mysql/ProductsDao");
const adao = require("../dao/mysql/AddressDao");
const cdao = require("../dao/mysql/CategoryDao");
router.get("/checkuid.do", ((req, res, next) => {
    if (req.query.uid) {
        udao.findByuid(req.query.uid).then(data => {
        if (data) {
          res.json({
            code: 200,
            msg: true
          })
        } else {
          res.json({
            code: 200,
            msg: false
          })
        }
      }).catch(err => next(err));
    } else {
      res.json({
        code: 404,
        msg: "没有传uid值"
      })
    }
  }));

  router.get("/checkpid.do", ((req, res, next) => {
    if (req.query.pid) {
      pdao.findBypid(req.query.pid).then(data => {
        if (data) {
          res.json({
            code: 200,
            msg: true
          })
        } else {
          res.json({
            code: 200,
            msg: false
          })
        }
      }).catch(err => next(err));
    } else {
      res.json({
        code: 404,
        msg: "没有传pid值"
      })
    }
  }));

  router.get("/checkaid.do", ((req, res, next) => {
    if (req.query.aid) {
      adao.findByaid(req.query.aid).then(data => {
        if (data) {
          res.json({
            code: 200,
            msg: true
          })
        } else {
          res.json({
            code: 200,
            msg: false
          })
        }
      }).catch(err => next(err));
    } else {
      res.json({
        code: 404,
        msg: "没有传aid值"
      })
    }
  }));
  router.get("/checkcid.do", ((req, res, next) => {
    if (req.query.cid) {
      cdao.findBycid(req.query.cid).then(data => {
        if (data) {
          res.json({
            code: 200,
            msg: true
          })
        } else {
          res.json({
            code: 200,
            msg: false
          })
        }
      }).catch(err => next(err));
    } else {
      res.json({
        code: 404,
        msg: "没有传cid值"
      })
    }
  }));
module.exports = router;
